package com.mebius.sys.service.impl;

import org.springframework.stereotype.Service;

import com.mebius.common.service.BaseTreeService;
import com.mebius.common.utils.BeanUtils;
import com.mebius.sys.entity.Resource;
import com.mebius.sys.service.ResourceService;
import com.mebius.sys.web.dto.ResourceDto;

@Service
public class ResourceImpl extends BaseTreeService<Resource> implements ResourceService {

	@Override
	public Resource add(ResourceDto dto) {
		Resource entity = new Resource();
		BeanUtils.copyNotNullProperties(dto, entity);

		entity.setWeight(this.nextWeight(entity.getParentId()));

		return this.hibernate.add(entity);
	}

	@Override
	public void delete(Long id) {
		this.hibernate.delete(Resource.class, id);
	}

	@Override
	public ResourceDto get(Long id) {
		ResourceDto dto = new ResourceDto();
		Resource resource = this.hibernate.get(Resource.class, id);
		BeanUtils.copyNotNullProperties(resource, dto);
		return dto;
	}

}
